<?php

namespace app\common;

#[\Attribute(\Attribute::TARGET_ALL | \Attribute::IS_REPEATABLE)]
class Attribute
{
    private string $title = "空组"; // 标题

    private array $request = []; //请求

    private array $middleware = []; //路由中间件

    private bool $isAuth; //权限 false不需要 true需要

    private bool $isPage; //是否页面 false不是 true是

    /**
     * 注解构造函数 function
     *
     * @param boolean $title 标题
     * @param boolean $isAuth 权限 false不需要 true需要
     * @param boolean $isPage 是否页面 false不是 true是
     * @param array $request 请求
     * @param array $middleware 路由中间件
     */
    public function __construct(
        string $title,
        bool $isAuth = false,
        bool $isPage = false,
        array $request = [],
        array $middleware = []
    ) {
        $this->title = $title;
        $this->request = $request;
        $this->middleware = $middleware;
        $this->isAuth =  $isAuth;
        $this->isPage =  $isPage;
    }

    /**
     * 路由数据 function
     *
     * @return array
     */
    public function route(): array
    {
        return [
            "request" => $this->request,
            "middleware" => $this->middleware
        ];
    }

    /**
     * 控制器数据 function
     *
     * @return array
     */
    public function fun(): array
    {
        return [
            "title" => $this->title,
            "isAuth" => $this->isAuth,
            "isPage" => $this->isPage,
        ];
    }

    /**
     * 标题 function
     *
     * @return string
     */
    public function title(): string
    {
        return $this->title;
    }
}
